package cn.dengta.webapp.trade.entity;

import java.util.Date;

import cn.dengta.common.model.Status;
import cn.dengta.webapp.base.entity.TimeBasedEntity;
import cn.dengta.webapp.trade.model.UserEquityType;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * 用户权益包
 *
 * @author xy
 * @since 2022-08-04
 */
@Setter
@Getter
@Accessors(chain = true)
@TableName("im_user_equity_bag")
public class UserEquityBag extends TimeBasedEntity {

	private static final long serialVersionUID = 1L;

	/** 用户id */
	private Long userId;
	/** 权益类型：1=视频卡；2=语音卡; 3=礼物; 4=头像框 */
	private UserEquityType type;
	/** 礼物id */
	private Long giftId;
	/** 礼物名称 */
	private String giftName;
	/** 权益所在周期 */
	private String period;
	/** 默认选中，1=选中，0=未选中 */
	private Integer master;
	/** 权益总数：{@code total = 单张卡的权益 * count } */
	private Integer total;
	/** 权益单位数 */
	private Integer count;
	/** 权益剩余总数：{@code remain = total - 已使用 } */
	private Integer remain;
	/** 结束日期 */
	private Date expireTime;

	public static UserEquityBag of(Long userId, String period, UserEquityType type, Date expireTime, Integer total) {
		UserEquityBag bag = new UserEquityBag();
		bag.setUserId(userId);
		bag.setPeriod(period);
		bag.setType(type);
		bag.setExpireTime(expireTime);
		bag.setTotal(total);
		bag.setRemain(total);
		bag.initTime(new Date());
		return bag;
	}

	public boolean master() {
		return Status.asResult(master);
	}

	public static final String USER_ID = "user_id";
	public static final String TYPE = "type";
	public static final String PERIOD = "period";
	public static final String MASTER = "master";
	public static final String TOTAL = "total";
	public static final String COUNT = "count";
	public static final String REMAIN = "remain";
	public static final String EXPIRE_TIME = "expire_time";

}
